<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('admin');

//初始化参数
$tbname = '#@__crm';
$gourl  = 'crm.php';
$action = isset($action) ? $action : '';


//添加管理员
if($action == 'add')
{

	$time = time();

	$sql = "INSERT INTO `$tbname` (school, truename, mobile, address, addtime, checkinfo,uid,gps,fulllog) VALUES ( '$school','$truename', '$mobile', '$address', '$time', '$checkinfo','$uid','$gps','$fulllog')";
	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//修改管理员
else if($action == 'update')
{


	
	$sql = "UPDATE `$tbname` SET school='$school', truename='$truename', mobile='$mobile', address='$address', checkinfo='$checkinfo',uid='$uid',gps='$gps',fulllog='$fulllog' WHERE `id`=$id";


	//批量替换 order表中的 uid
	if(intval($uid)>0){
        $dosql->ExecNoneQuery("UPDATE  `#@__order`  SET uid='$uid'  WHERE `crmid`=$id");
	}


	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//修改管理员审核状态
else if($action == 'check')
{

	if($checkinfo == '1')
		$sql = "UPDATE `$tbname` SET checkinfo='0' WHERE `id`=$id";
	if($checkinfo == '0')
		$sql = "UPDATE `$tbname` SET checkinfo='1' WHERE `id`=$id";


	if($dosql->ExecNoneQuery($sql))
	{
    	header("location:$gourl");
		exit();
	}
}


//删除管理员
else if($action == 'del')
{
	if($_SESSION['adminlevel']!='1')
	{
		ShowMsg('抱歉，不能删除 ,请联系管理员！','-1');
		exit();
	}

	if($dosql->ExecNoneQuery("DELETE FROM `$tbname` WHERE `id`=$id"))
	{
    	header("location:$gourl");
		exit();
	}
}


//无条件返回
else
{
    header("location:$gourl");
	exit();
}
?>
